#include <iostream>
#include <vector>
using namespace std;
class Solution {
private:
    void dfs(vector<vector<int>>& image,int sr,int sc,int newColor,int oldColor)
    {
        if(sr < 0 || sr >= image.size() || sc >= image[0].size() || image[sr][sc] != oldColor)
            return;
        image[sr][sc] = newColor;
        dfs(image,sr-1,sc,newColor,oldColor);
        dfs(image,sr+1,sc,newColor,oldColor);
        dfs(image,sr,sc-1,newColor,oldColor);
        dfs(image,sr,sc+1,newColor,oldColor);
    }
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {
        if(newColor == image[sr][sc]) return image;
        dfs(image,sr,sc,newColor,image[sr][sc]);
        return image;
    }
};

int main()
{
    vector<vector<int>> image;
    vector<int> temp = {1,1,1};
    image.push_back(temp);
    vector<int> temp1 = {1,1,0};
    image.push_back(temp1);
    vector<int> temp2 = {1,0,1};
    image.push_back(temp2);
    Solution sol;
    sol.floodFill(image,1,1,2);
    return 0;
}